﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>验证列表框中的值是否重复</title>
    <script type="text/javascript" language="JavaScript">
        function chk(){
            let txtValue = document.getElementById("txtValue");
            let sel = document.getElementById("sel");
            for(let i = 0;i< sel.length;i++){
                if(txtValue.value === sel.options[i].text){
                    alert("该值已经存在");
                }
            }
        }
        
    </script>
</head>
<body>
<div id="mydiv">
    <select id="sel" name="sel">
        <option>China</option>
        <option>England</option>
        <option>German</option>
    </select>
    <input type="text" name="txtValue" id="txtValue"><br/>
    <input type="button" value="检测是否存在" onclick="chk();">
</div>
</body>
</html>